package com.ty.controller;

import com.google.common.collect.Maps;
import com.ty.model.AjaxResult;
import com.ty.service.LookupService;
import com.ty.utils.WebIpUtil;
import com.ty.utils.ip.IPLocation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * IP归属地查询Controller
 *
 * @Author Tommy
 * @Date 2022/10/23
 */
@RestController
@Slf4j
public class LookupController {

    @Autowired
    private LookupService lookupService;

    /**
     * 获取语言资源包
     */
    @RequestMapping("/ip/lookup")
    public AjaxResult lookup(@RequestParam String ip) throws Exception {
        ip = WebIpUtil.checkIP(ip)? ip : WebIpUtil.getClientIP();
        log.debug("待解析IP: " + ip);
        return AjaxResult.success(lookupService.lookup(ip));
    }
}
